<template>
  <view class="container">
    <!-- 页面头部标题 -->
    <view class="new-page-header">
      <!-- 状态栏占位 -->
      <view class="new-status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
      <!-- 导航栏 -->
      <view class="new-nav-bar" :style="{ height: navBarHeight + 'px' }">
        <!-- 返回按钮 -->
        <view class="new-back-button" @click="goBack">
          <u-icon name="arrow-left" size="36" color="#ffffff"></u-icon>
        </view>
        <!-- 标题 -->
        <view class="new-header-title" :style="{ lineHeight: navBarHeight + 'px' }">订单详情</view>
      </view>
    </view>

    <!-- 页面内容 -->
    <view class="page-content">
      <!-- 设备信息 -->
      <view class="device-info">
        <view class="info-title">设备信息</view>
        <view class="info-row">
          <view class="info-label">设备名称</view>
          <view class="info-value">陪护床</view>
        </view>
        <view class="info-row">
          <view class="info-label">设备编号</view>
          <view class="info-value">100005</view>
        </view>
        <view class="info-row">
          <view class="info-label">开始时间</view>
          <view class="info-value">
            <!-- {{ orderInfo. }} -->
            {{ startTime }}
            <!-- 2025年05月01日
            <text class="time-highlight green">00时00分</text> -->
          </view>
        </view>
        <view class="info-row">
          <view class="info-label">到期时间</view>
          <view class="info-value">
            {{ endTime }}
            <!-- 2025年05月01日
            <text class="time-highlight red">07时00分</text> -->
          </view>
        </view>
        <view class="info-row">
          <view class="info-label">收费标准</view>
          <view class="info-value">{{ orderInfo.hospital_price }}元/小时</view>
        </view>
        <view class="info-row">
          <view class="info-label">预计金额</view>
          <view class="info-value">
            <text class="price">{{ orderInfo.money }}</text>
            <text class="duration-hint">元 </text>
          </view>
        </view>
        <view class="info-row">
          <view class="info-label">押金金额</view>
          <view class="info-value">
            <text class="price">{{ orderInfo.deposit_money }}</text>
            <text class="duration-hint">元</text>
          </view>
        </view>
      </view>

      <!-- 订单号码 -->
      <view class="device-info">
        <view class="order-number-card">
          <view class="order-title">订单号码</view>
          <view class="order-number">
            <text class="number-text">{{ orderInfo.sn }}</text>
            <text class="copy-btn" @click="copyOrderNumber">复制</text>
          </view>
        </view>
      </view>

      <!-- 提示信息 -->
      <view class="notice-info">
        <view class="notice-item">
          <text class="notice-star">*</text>
          <text class="notice-text">请在到期时间前归还</text>
        </view>
        <view class="notice-item">
          <text class="notice-star">*</text>
          <text class="notice-text">超时使用将按<text class="highlight">{{
            orderInfo.overtime_money
          }}</text>元/小时扣费，日封顶<text class="highlight">20</text>元</text>
        </view>
        <view class="notice-item">
          <text class="notice-star">*</text>
          <text class="notice-text">归还之后<text class="highlight">押金</text>将会原路返回</text>
        </view>
      </view>

      <!-- 操作按钮 -->
      <view class="action-buttons">
        <view class="action-btn unlock-btn" @click="unlockDevice">
          <text class="btn-text">免费开锁</text>
        </view>
        <view class="action-btn return-btn" @click="handleReturn">
          <text class="btn-text">确认归还</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import dayjs from 'dayjs';
import navbarMixin from '@/common/mixin/navbar.js';
import { getOrderDetail, endOrder, sendOpenLock } from '@/api/index.js';
// AES加密库（需要自行引入或实现）
const CryptoJS = require('crypto-js');
var fun_aes = require('utils/aes.js');
export default {
  mixins: [navbarMixin],

  data() {
    return {
      // 是否处于无蓝牙状态
      noBluetooth: false,
      tokenCmd: [6, 1, 1, 1, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12],
      // 扫码结果
      scanCode: '',
      // 扫码类型
      scanType: 'return',

      serviceId: '0000FEE7-0000-1000-8000-00805F9B34FB',
      writeCharId: '000036F5-0000-1000-8000-00805F9B34FB',
      readCharId: '0000FEC9-0000-1000-8000-00805F9B34FB',
      notifyCharId: '000036F6-0000-1000-8000-00805F9B34FB',

      // 锁舌状态
      lockStatus: '',
      // 磁铁状态
      magnetStatus: '',

      // 订单号
      orderNumber: '100545054500000',

      // 设备名称
      deviceName: '',
      // 设备编号
      deviceNumber: '',
      // 开始时间
      startTime: '',
      // 结束时间
      endTime: '',
      // 收费标准
      chargeStandard: '',
      // 预计金额
      expectedAmount: '',
      // 押金金额
      depositAmount: '',

      orderId: '',

      token: '',

      orderInfo: {},

      equipmentInfo: {},
    };
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    this.scanCode = decodeURIComponent(options.code || '');
    this.scanType = options.type || 'return';
    await this.getOrderInfo();
    await this.initBluetooth();
  },
  onUnload() {
    if (this.currentDeviceId) {
      uni.closeBLEConnection({ deviceId: this.currentDeviceId });
    }

    uni.stopBluetoothDevicesDiscovery();
  },

  methods: {
    // AES加密
    encryptData(data) {
      try {
        const aesKey = [
          0x3a, 0x60, 0x43, 0x2a, 0x5c, 0x01, 0x21, 0x1f, 0x29, 0x1e, 0x0f,
          0x4e, 0x0c, 0x13, 0x28, 0x25,
        ];
        const keyBytes = CryptoJS.enc.Utf8.parse(new Int8Array(aesKey));
        const dataBytes = CryptoJS.enc.Utf8.parse(data);
        // AES-128 ECB模式加密，无填充
        const encrypted = CryptoJS.AES.encrypt(dataBytes, keyBytes, {
          mode: CryptoJS.mode.ECB,
          padding: CryptoJS.pad.NoPadding,
        });

        // 返回Uint8Array
        return new Int8Array(encrypted.ciphertext.words);
      } catch (e) {
        console.error('加密失败:', e);
        return null;
      }
    },
    aesEncrypt: function (array) {
      const INITIAL_KEY = [
        0x3a, 0x60, 0x43, 0x2a, 0x5c, 0x01, 0x21, 0x1f, 0x29, 0x1e, 0x0f, 0x4e,
        0x0c, 0x13, 0x28, 0x25,
      ];

      var acontent = array;
      var contentWA = fun_aes.CryptoJS.enc.int8array.parse(acontent);

      const key = fun_aes.CryptoJS.enc.int8array.parse(INITIAL_KEY);

      const encrypted = fun_aes.CryptoJS.AES.encrypt(contentWA, key, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.NoPadding,
      });

      var bv = fun_aes.CryptoJS.enc.int8array.stringify(encrypted.ciphertext);

      return bv;
    },
    // 解析广播数据
    parseAdvertData(buffer) {
      try {
        if (!buffer || buffer.byteLength < 9) return null;

        const dataView = new DataView(buffer);
        // 前2字节是PRO
        const PRO = dataView.getUint16(0, false).toString(16).padStart(4, '0');
        // 接下来6字节是MAC地址
        const MAC = Array.from({ length: 6 }, (_, i) =>
          dataView
            .getUint8(2 + i)
            .toString(16)
            .padStart(2, '0'),
        ).join(':');
        // 第9字节是电量(0-100)
        const POWER = dataView.getUint8(8);
        // 第10字节是锁状态(如果有)
        const LOCK_STATE = buffer.byteLength > 9 ? dataView.getUint8(9) : null;

        return { PRO, MAC, POWER, LOCK_STATE };
      } catch (e) {
        console.error('解析广播数据失败:', e);
        return null;
      }
    },
    // 扫描设备
    scanDevices() {
      console.log('开始扫描设备...');
      this.devices = [];
      uni.startBluetoothDevicesDiscovery({
        services: ['FEE7'],
        success: (res) => {
          console.log('扫描已启动', res);

          // 3秒后自动停止扫描
          // setTimeout(() => {
          //   uni.stopBluetoothDevicesDiscovery();
          //   console.log("扫描已停止");
          // }, 15000);
        },
        fail: (err) => {
          console.log('扫描失败: ' + JSON.stringify(err));
          console.log('errerr', err);
        },
      });
    },
    // 初始化蓝牙适配器
    initBluetooth() {
      const that = this;
      uni.openBluetoothAdapter({
        success: (res) => {
          console.log('蓝牙适配器初始化成功');
          that.listenBluetoothEvents();

          setTimeout(() => {
            // 开始扫描
            that.scanDevices();
          }, 500);
        },
        fail: (err) => {
          console.log('蓝牙适配器初始化失败: ' + JSON.stringify(err));
          // uni.showToast({
          //   title: "请打开蓝牙后重新扫码",
          //   icon: "none",
          // });
          that.noBluetooth = true;
        },
      });
    },
    arrayBufferToHexString: function (buffer) {
      if (buffer != '[object ArrayBuffer]') {
        return;
      }
      let dataView = new DataView(buffer);

      var hexStr = '';
      for (var i = 0; i < dataView.byteLength; i++) {
        var str = dataView.getUint8(i);
        var hex = (str & 0xff).toString(16);
        hex = hex.length === 1 ? '0' + hex : hex;
        hexStr += hex;
      }

      return hexStr.toUpperCase();
    },
    // 监听蓝牙事件
    listenBluetoothEvents() {
      console.log('开始监听蓝牙事件');

      // 监听蓝牙适配器状态变化
      // uni.onBluetoothAdapterStateChange((res) => {});

      // 监听设备发现事件
      uni.onBluetoothDeviceFound(async (res) => {
        console.log('resresresres', res);

        res.devices.forEach((device) => {
          if (!device.advertisData) return;

          // 解析广播数据
          // const parsedData = this.parseAdvertData(device.advertisData);

          var macAddressTmp = this.arrayBufferToHexString(device.advertisData);

          var tmpLength = macAddressTmp.length;

          if (tmpLength >= 16) {
            var macAddress =
              macAddressTmp.substring(4, 6) +
              ':' +
              macAddressTmp.substring(6, 8) +
              ':' +
              macAddressTmp.substring(8, 10) +
              ':' +
              macAddressTmp.substring(10, 12) +
              ':' +
              macAddressTmp.substring(12, 14) +
              ':' +
              macAddressTmp.substring(14, 16);
          }

          console.log('macAddress', {
            macAddress,
            'this.currentDeviceMac': this.currentDeviceMac,
            duidui: macAddress === this.currentDeviceMac,
          });

          if (macAddress === this.currentDeviceMac) {
            console.log('找到对应的蓝牙设备拉', {
              macAddress,
              device: device,
            });

            this.currentDeviceId = device.deviceId;

            // 开始连接
            this.connectDevice(device.deviceId);
          }
        });
      });
    },
    // bleGetToken: async function () {
    //   //命令格式
    //   console.log("开始获取token");

    //   //0x06	0x01	0x01	0x01
    //   const _token = [];
    //   const _that = this;
    //   for (let i = 0; i < _that.tokenCmd.length; i++) {
    //     if (i <= 3) {
    //       //
    //       _token.push(_that.tokenCmd[i]);
    //       continue;
    //     }
    //     const _num = Math.round(Math.random() * 100);
    //     _that.tokenCmd.splice(i, 1, _num);
    //     _token.push(_num);
    //   }

    //  await _that.commDevice(_token);
    // },
    bleGetToken: async function () {
      // 命令格式
      console.log('开始获取token');

      // 0x06	0x01	0x01	0x01
      const _token = [];
      const _that = this;
      for (let i = 0; i < _that.tokenCmd.length; i++) {
        if (i <= 3) {
          _token.push(_that.tokenCmd[i]);
          continue;
        }
        const _num = Math.round(Math.random() * 100);
        _that.tokenCmd.splice(i, 1, _num);
        _token.push(_num);
      }

      // 添加重试机制，最多重试3次
      let retryCount = 0;
      const maxRetries = 3;

      while (retryCount < maxRetries) {
        try {
          // 设置5秒超时
          const timeoutPromise = new Promise((_, reject) => {
            setTimeout(() => reject(new Error('timeout')), 5000);
          });

          // 执行commDevice并等待结果
          await Promise.race([_that.commDevice(_token), timeoutPromise]);

          // 如果成功执行，跳出循环
          console.log(`Token获取成功，尝试次数: ${retryCount + 1}`);
          break;
        } catch (error) {
          retryCount++;
          console.log(`Token获取失败，第${retryCount}次重试`, error);

          if (retryCount >= maxRetries) {
            throw new Error(`获取Token失败，已重试${maxRetries}次`);
          }

          // 可选：在重试前稍作延迟
          await new Promise((resolve) => setTimeout(resolve, 1000));
        }
      }
    },
    // AES解密
    decryptData(data) {
      var that = this;
      var acontent = data;
      // 将密文转换成WordArray
      var contentWA = fun_aes.CryptoJS.enc.int8array.parse(acontent);
      // 插件要求密文是base64格式
      var dcBase64String = contentWA.toString(fun_aes.CryptoJS.enc.Base64);

      const INITIAL_KEY = [
        0x3a, 0x60, 0x43, 0x2a, 0x5c, 0x01, 0x21, 0x1f, 0x29, 0x1e, 0x0f, 0x4e,
        0x0c, 0x13, 0x28, 0x25,
      ];

      const key = fun_aes.CryptoJS.enc.int8array.parse(INITIAL_KEY);

      // 解密 选定mode是CFB类型，无偏移量
      var decrypted = fun_aes.CryptoJS.AES.decrypt(dcBase64String, key, {
        // iv: that.globalData.bleVariable.ivWA,
        mode: fun_aes.CryptoJS.mode.ECB,
        padding: fun_aes.CryptoJS.pad.NoPadding,
      });
      console.log('解密了，内容是=== ' + decrypted);
      // 将解密后的明文转回int8数组
      var bv = fun_aes.CryptoJS.enc.int8array.stringify(decrypted);
      return bv;
    },

    // 等待Token响应
    waitForTokenResponse(timeout) {
      return new Promise((resolve) => {
        let timer;

        // 临时监听Token响应
        const handler = (res) => {
          console.log('接受token相应', res.value);

          const result = res.value;
          var resultArray = new Int8Array(result);

          const decrypted = this.decryptData(resultArray);

          console.log('接受到蓝牙的回调了哈', decrypted);

          if (!decrypted) return;

          // 检查是否为Token响应 (0x06 0x02)
          if (decrypted[0] == 6 && decrypted[1] == 2) {
            const _token = decrypted.slice(3, 7);

            clearTimeout(timer);
            uni.offBLECharacteristicValueChange(handler);

            // this.getDeviceBattery(_token);
            this.queryLockStatus(_token);

            this.token = _token;
            resolve(_token); // 提取4字节Token
          } else if (
            decrypted[0] == 2 &&
            decrypted[1] == 2 &&
            decrypted[2] == 1
          ) {
            // 电量回调
            console.log('获取到电量了', decrypted[3]);

            this.batteryPercentage = decrypted[3];

            reportPower({
              device_code: this.scanCode,
              battery_level: decrypted[3],
            });
          } else if (
            decrypted[0] == 5 &&
            decrypted[1] == 15
            // &&
            // decrypted[2] == 2
          ) {
            // 获取锁状态
            console.log('获取锁状态了', decrypted);

            resolve(decrypted);

            this.magnetStatus = decrypted[3] == 1;
            // 1标示关锁，0开锁
            this.lockStatus = decrypted[4] == 1;
          }
        };

        uni.onBLECharacteristicValueChange(handler);

        // 设置超时
        timer = setTimeout(() => {
          uni.offBLECharacteristicValueChange(handler);
          resolve(null);
        }, timeout);
      });
    },
    async lockDevice() {
      let _locakCmd = [5, 12, 1, 1];

      this.token.forEach((item, index) => {
        _locakCmd.push(item);
      });

      for (let i = 0; i <= 7; i++) {
        _locakCmd.push(Math.round(Math.random() * 100));
      }

      return this.commDevice(_locakCmd, 'lockDevice');
    },

    // 连接设备
    connectDevice(deviceId) {
      if (!deviceId) {
        console.log('请先选择设备');
        return;
      }

      uni.createBLEConnection({
        deviceId: deviceId,
        success: (res) => {
          this.getDeviceServices();
          console.log('连接成功', res);
        },
        fail: (err) => { },
      });
    },
    // 获取设备服务
    getDeviceServices() {
      const _that = this;
      uni.getBLEDeviceServices({
        deviceId: this.currentDeviceId,
        success: (res) => {
          this.getDeviceCharacteristics();

          console.log('获取蓝牙设备所有服务(service)', res);
        },
        fail: (err) => {
          console.log('获取服务失败: ' + JSON.stringify(err));
        },
      });
    },
    // 获取特征值
    getDeviceCharacteristics() {
      const _that = this;
      uni.getBLEDeviceCharacteristics({
        deviceId: this.currentDeviceId,
        serviceId: this.serviceId,
        success: (res) => {
          wx.onBLECharacteristicValueChange(function (characteristic) {
            console.log('监听特征值变化', characteristic);
          });

          wx.notifyBLECharacteristicValueChange({
            deviceId: this.currentDeviceId,
            serviceId: this.serviceId,
            characteristicId: this.notifyCharId,
            state: true,
            success: (res) => {
              console.log('已启用通知', res);
              setTimeout(() => {
                _that.bleGetToken();
              }, 500);
            },
            fail: (err) => {
              console.log('启用通知失败: ' + JSON.stringify(err));
            },
            complete: (res) => {
              uni.onBLECharacteristicValueChange((res) => {
                console.log('接收到数据', res);
              });
            },
            type: 'notification',
          });
        },
        fail: (err) => { },
      });
    },

    // 开锁功能
    async unlockDevice() {
      if (this.noBluetooth && this.equipmentInfo.hardware_type == 2) {
        return sendOpenLock({
          orderId: this.orderInfo.id,
        });
      }

      // 如果是1拖5
      if (this.equipmentInfo.hardware_type == 3) {
        return sendOpenLock({
          orderId: this.orderInfo.id,
        });
      }


      let _locakCmd = [5, 1, 6];

      for (let i = 0; i <= 5; i++) {
        _locakCmd.push(48);
      }

      this.token.forEach((item) => {
        _locakCmd.push(item);
      });

      // 三个随机数
      for (let i = 0; i < 3; i++) {
        const _num = Math.round(Math.random() * 100);
        _locakCmd.push(_num);
      }

      const encrypted = this.aesEncrypt(_locakCmd);
      if (!encrypted) {
        throw new Error('加密失败');
      }

      await this.writeBLEValue(encrypted.buffer);
    },

    async lockDevice() {
      let _locakCmd = [5, 12, 1, 1];

      this.token.forEach((item, index) => {
        _locakCmd.push(item);
      });

      for (let i = 0; i <= 7; i++) {
        _locakCmd.push(Math.round(Math.random() * 100));
      }

      const encrypted = this.aesEncrypt(_locakCmd);
      if (!encrypted) {
        throw new Error('加密失败');
      }

      await this.writeBLEValue(encrypted.buffer);
    },
    // 获取设备电量
    async getDeviceBattery(token) {
      let _locakCmd = [2, 1, 1, 1];

      token.forEach((item, index) => {
        _locakCmd.push(item);
      });

      for (let i = 0; i <= 7; i++) {
        _locakCmd.push(Math.round(Math.random() * 100));
      }

      this.commDevice(_locakCmd, 'getDeviceBattery');
    },
    // 查询锁状态
    async queryLockStatus(token) {
      let _locakCmd = [5, 14, 1, 1];

      token.forEach((item, index) => {
        _locakCmd.push(item);
      });

      for (let i = 0; i <= 7; i++) {
        _locakCmd.push(Math.round(Math.random() * 100));
      }

      await this.commDevice(_locakCmd, 'queryLockStatus');
    },

    // 封装BLE写入操作
    writeBLEValue(value) {
      return new Promise((resolve, reject) => {
        uni.writeBLECharacteristicValue({
          deviceId: this.currentDeviceId,
          serviceId: this.serviceId,
          characteristicId: this.writeCharId,
          value: value,
          success: resolve,
          fail: reject,
        });
      });
    },
    // 通过设备id去创建订单
    async getOrderInfo() {

      const status = this.scanType === 'view' ? 3 : 1;

      console.log("statusstatusstatus", status)
      try {
        const _res = await getOrderDetail({
          kpl: this.scanCode,
          status: status
        });

        if (!_res?.order) {
          return uni.showModal({
            title: '提示',
            content: '该订单不存在，请返回',
            showCancel: false,
            success: function () {
              uni.navigateBack({
                delta: 1,
              });
            },
          });
        }

        this.orderId = _res?.order?.id;

        this.currentDeviceMac = _res?.equipment_info?.mac;

        this.orderInfo = _res.order;

        this.equipmentInfo = _res.equipment;

        this.deviceName = _res.equipment_info.devicename;
        this.deviceNumber = _res.equipment_info.deviceno;
        // 使用day转换日期时间
        this.startTime = dayjs(_res.order.createtime * 1000).format(
          'YYYY-MM-DD HH:mm:ss',
        );
        this.endTime = dayjs(_res.order.answer_return_time * 1000).format(
          'YYYY-MM-DD HH:mm:ss',
        );
        this.chargeStandard = _res?.order?.hospital_price;
        this.expectedAmount = _res?.order?.money;
        this.depositAmount = _res?.$hospital?.deposit_price;
      } catch (error) { }
    },
    /**
     * 返回上一页
     */
    goBack() {
      uni.navigateBack({
        delta: 1,
      });
    },

    /**
     * 复制订单号
     */
    copyOrderNumber() {
      uni.setClipboardData({
        data: this.orderNumber,
        success: () => {
          uni.showToast({
            title: '已复制订单号',
            icon: 'success',
          });
        },
      });
    },

    /**
     * 处理确认归还
     */
    async handleReturn() {
      uni.showLoading({
        title: '正在归还设备...',
      });
      let _locakCmd = [5, 14, 1, 1];

      this.$nextTick(async () => {
        this.token.forEach((item, index) => {
          _locakCmd.push(item);
        });

        for (let i = 0; i <= 7; i++) {
          _locakCmd.push(Math.round(Math.random() * 100));
        }

        try {
          const _res = await this.commDevice(_locakCmd, 'queryLockStatus');
          if (!_res) {
            return uni.showToast({
              title: '设备状态异常，请重试',
              icon: 'none',
            });
          }

          if (_res?.[3] != 1) {
            return uni.showToast({
              title: '锁的磁铁处未吸紧，请检查',
              icon: 'error',
            });
          }
          if (_res?.[4] == 1) {
            return uni.showToast({
              title: '锁舌未伸出，请检查后重试',
              icon: 'none',
            });
          }

          // this.magnetStatus = _res[3] == 1;
          // 1标示关锁，0开锁
          // this.lockStatus = _res[4] == 1;
        } catch (error) {
          console.log('error', error);
        }
      });

      console.log('正确流程');

      const _that = this;
      uni.showModal({
        title: '确认归还',
        content: '确定要归还此设备吗？归还后押金将原路返回。',
        success: async (res) => {
          if (res.confirm) {
            await endOrder({
              order_id: _that.orderId,
            });

            // uni.showToast({
            //   title: "归还成功",
            //   icon: "success",
            // });

            // 返回
            uni.navigateBack({
              delta: 1,
            });
          }
        },
      });
    },
    /**
     * 与设备交互
     */
    commDevice: async function (cmd) {
      // return _data;

      return new Promise(async (resolve, reject) => {
        const encrypted = this.aesEncrypt(cmd);

        await this.writeBLEValue(encrypted.buffer);
        // 等待Token响应 (超时5秒)
        const _data = await this.waitForTokenResponse(10000);
        console.log('获取到蓝牙的回调了', _data);
        if (_data) {
          resolve(_data);
        } else {
          reject('获取蓝牙回调超时');
        }
      });
    },
  },

  /**
   * 分享当前页面
   */
  onShareAppMessage() {
    return {
      title: '归还订单',
      path: '/pages/newreturn/index',
    };
  },
};
</script>

<style lang="scss" scoped>
.container {
  min-height: 100vh;
  background: #f8f9fa;
  padding-bottom: 120rpx;
}

.page-header {
  background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
  padding: 60rpx 40rpx 30rpx;
  display: flex;
  align-items: center;
  position: relative;

  .back-button {
    position: absolute;
    left: 40rpx;
    top: 50%;
    transform: translateY(-23%);
    width: 60rpx;
    height: 60rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
  }

  .header-title {
    font-size: 36rpx;
    font-weight: bold;
    color: #ffffff;
    text-align: center;
    text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
    flex: 1;
  }
}

.device-info {
  background: #ffffff;
  margin: 30rpx;
  border-radius: 20rpx;
  padding: 40rpx 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);

  .info-title {
    font-size: 32rpx;
    font-weight: 600;
    color: #333333;
    margin-bottom: 30rpx;
  }

  .info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx 0;
    border-bottom: 1rpx solid #f5f5f5;

    &:last-child {
      border-bottom: none;
    }

    .info-label {
      font-size: 28rpx;
      color: #999999;
    }

    .info-value {
      font-size: 28rpx;
      color: #333333;
      text-align: right;
      display: flex;
      align-items: center;
      gap: 16rpx;

      .price {
        color: #74b9ff;
        font-size: 24rpx;
      }

      .duration-hint {
        font-size: 24rpx;
        color: rgb(0, 0, 0);
      }

      .time-highlight {
        &.green {
          color: #00b894;
        }

        &.red {
          color: #fd79a8;
        }
      }
    }
  }
}

.order-number-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0rpx 0;
  border-bottom: 1rpx solid #f5f5f5;

  .order-title {
    font-size: 28rpx;
    color: #999999;
  }

  .order-number {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: right;

    .number-text {
      font-size: 28rpx;
      color: #333333;
    }

    .copy-btn {
      background: #74b9ff;
      color: #ffffff;
      font-size: 24rpx;
      margin-left: 24rpx;
      padding: 8rpx 16rpx;
      border-radius: 24rpx;
    }
  }
}

.notice-info {
  background: #ffffff;
  margin: 30rpx;
  border-radius: 20rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);

  .notice-item {
    display: flex;
    align-items: flex-start;
    margin-bottom: 16rpx;

    &:last-child {
      margin-bottom: 0;
    }

    .notice-star {
      color: #fd79a8;
      font-size: 24rpx;
      margin-right: 8rpx;
      line-height: 1.5;
    }

    .notice-text {
      flex: 1;
      font-size: 24rpx;
      color: #666666;
      line-height: 1.5;

      .highlight {
        color: #74b9ff;
        font-weight: 600;
      }
    }
  }
}

.action-buttons {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 30rpx;
  display: flex;
  flex-direction: column;
  gap: 20rpx;

  .action-btn {
    width: 100%;
    height: 100rpx;
    border-radius: 100rpx;
    display: flex;
    align-items: center;
    justify-content: center;

    .btn-text {
      font-size: 32rpx;
      font-weight: 600;
    }

    &.unlock-btn {
      background: linear-gradient(135deg, #00b894 0%, #00a085 100%);
      box-shadow: 0 8rpx 24rpx rgba(0, 184, 148, 0.4);

      .btn-text {
        color: #ffffff;
      }

      &:active {
        transform: translateY(2rpx);
        box-shadow: 0 6rpx 20rpx rgba(0, 184, 148, 0.5);
      }
    }

    &.return-btn {
      background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
      box-shadow: 0 8rpx 24rpx rgba(116, 185, 255, 0.4);

      .btn-text {
        color: #ffffff;
      }

      &:active {
        transform: translateY(2rpx);
        box-shadow: 0 6rpx 20rpx rgba(116, 185, 255, 0.5);
      }
    }
  }
}
</style>
